package com.xing.netty;

import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;

public class BioClient {
    static final ByteBuffer buffer = ByteBuffer.allocate(512);

    public static void main(String[] args) throws Exception{
        Socket socket = new Socket("127.0.0.1", 8888);
        for (;;) {
            try {
                String message = "hello world";
                socket.getOutputStream().write(message.getBytes());
                TimeUnit.SECONDS.sleep(3);

                buffer.clear();
                int read = socket.getInputStream().read(buffer.array());
                System.out.println(new String(buffer.array(), 0, read));
            } catch (Exception e) {
                System.out.println("写数据错误！");
            }
        }
    }
}
